var commanderuUserobj = {
    // /** @param {Object} creepList**/
    // /** @param {Object} room **/
    /** @param {Game} Game**/
    run: function () {
        var harvesterList = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
        var upgraderList = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
        var constructerList = _.filter(Game.creeps, (creep) => creep.memory.role == 'constructer');
        var explorerList = _.filter(Game.creeps, (creep) => creep.memory.role == 'explorer');
        var uintNum = [harvesterList.length, upgraderList.length, constructerList.length, explorerList.length];
        var roleSetting = { harvester: 4, upgrader: 2, constructer: 4, explorer: 0 };
        var spawns = Game.spawns
        console.log(uintNum)

        if (upgraderList.length < roleSetting.upgrader) {
            console.log('need a upgrader');
            for (const sp in spawns) {
                let sname = "U" + String(Math.floor((Math.random() * 100) + 1));
                if (Game.creeps[sname] == true) {
                    console.log(sname, ' been used');
                    continue;
                }
                if (Game.spawns[sp].spawnCreep([WORK, CARRY, CARRY, MOVE], sname, { memory: { role: 'upgrader' } }) == ERR_NOT_ENOUGH_ENERGY) {
                    console.log(sp, 'NOT_ENOUGH_ENERGY');
                    continue;
                }
            }
        }

        if (harvesterList.length < roleSetting.harvester) {
            console.log('need a harvester');
            for (const sp in spawns) {
                let sname = "H" + String(Math.floor((Math.random() * 100) + 1));
                if (Game.creeps[sname] == true) {
                    console.log(sname, ' been used');
                    continue;
                }
                if (Game.spawns[sp].spawnCreep([WORK, CARRY, MOVE], sname, { memory: { role: 'harvester' } }) == ERR_NOT_ENOUGH_ENERGY) {
                    console.log(sp, 'NOT_ENOUGH_ENERGY');
                    continue;
                }
            }
        }

        if (constructerList.length < roleSetting.constructer) {
            console.log('need a constructer');
            for (const sp in spawns) {
                let sname = "C" + String(Math.floor((Math.random() * 100) + 1));
                if (Game.creeps[sname] == true) {
                    console.log(sname, ' been used');
                    continue;
                }
                if (Game.spawns[sp].spawnCreep([WORK, CARRY, CARRY, MOVE, MOVE], sname, { memory: { role: 'constructer' } }) == ERR_NOT_ENOUGH_ENERGY) {
                    console.log(sp, 'NOT_ENOUGH_ENERGY');
                    continue;
                }
            }
        }

        if (explorerList.length < roleSetting.explorer) {
            console.log('need a explorer');
            for (const sp in spawns) {
                let sname = "E" + String(Math.floor((Math.random() * 100) + 1));
                if (Game.creeps[sname] == true) {
                    console.log(sname, ' been used');
                    continue;
                }
                if (Game.spawns[sp].spawnCreep([MOVE, MOVE, MOVE], sname, { memory: { role: 'explorer' } }) == ERR_NOT_ENOUGH_ENERGY) {
                    console.log(sp, 'NOT_ENOUGH_ENERGY');
                    continue;
                }
            }
        }

    }
}

module.exports = commanderuUserobj;


// if (upgraderList.length < 5) {
//     console.log('need a upgrader');
//     for (const sp in spawns) {
//         let sname = "U" + String(Math.floor((Math.random() * 100) + 1));
//         if (Game.creeps[sname] == true) {
//             console.log(sname, ' been used');
//             continue;
//         }
//         if (Game.spawns[sp].spawnCreep([WORK, CARRY, CARRY, MOVE], sname, { memory: { role: 'upgrader' } }) == ERR_NOT_ENOUGH_ENERGY) {
//             console.log(sp, 'NOT_ENOUGH_ENERGY');
//             continue;
//         }
//     }
// }
